package com.jack.thinking.thread.group;

public class RunTest {
	public static void main(String[] args) {
		ThreadGroup mainGroup = Thread.currentThread().getThreadGroup();
		System.out.println("main>" + mainGroup);
		
		ThreadGroup sonGroup1 = new ThreadGroup(mainGroup, "my id is sonGroup1");
		
		Thread son1 = new Thread(mainGroup, new Runnable() {
			@Override
			public void run() {
				try {
					Thread.sleep(10);
				} catch (InterruptedException e) {
				}
			}
		}, "son1");
		son1.start();
		
		Thread son2 = new Thread(mainGroup, new Runnable() {
			@Override
			public void run() {
				try {
					Thread.sleep(10);
				} catch (InterruptedException e) {
				}
			}
		}, "son2");
		son2.start();
		
		Thread grandSon1 = new Thread(sonGroup1, new Runnable() {
			@Override
			public void run() {
				try {
					Thread.sleep(10);
				} catch (InterruptedException e) {
				}
			}
		}, "grandSon1");
		grandSon1.start();
		
		Thread grandSon2 = new Thread(sonGroup1, new Runnable() {
			@Override
			public void run() {
				try {
					Thread.sleep(10);
				} catch (InterruptedException e) {
				}
			}
		}, "grandSon2");
		grandSon2.start();
		
		Thread[] list = new Thread[Thread.currentThread().getThreadGroup().activeCount()];
		Thread.currentThread().getThreadGroup().enumerate(list, false);
		
		for(Thread t : list) {
			System.out.println("item:" + (t == null ? "NULL" : t.getName()));
		}
		
		System.out.println(Thread.currentThread().getThreadGroup().getParent());
	}
}
